home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / pcl4b42 / term_io.bas < prev    next >
BASIC Source File  |  1995-05-09  |  3KB  |  118 lines

  1. '  -- TERM_IO.PAS --
  2. '
  3. '  This program is donated to the Public
  4. '  Domain by MarshallSoft Computing, Inc.
  5. '  It is provided as an example of the use
  6. '  of the Personal Communications Library.
  7. '
  8.  
  9. DefInt A-Z
  10.  
  11. '$INCLUDE: 'PCL4B.BI'
  12. '$INCLUDE: 'TERM_IO.BI'
  13.  
  14. Const CR = 13, ESC = 27, BS = 8
  15. Const BLK = 32, CAN = 24
  16.  
  17. Const LowVideo = 7
  18. Const HighVideo = 1
  19.  
  20. '** match baud rate string
  21.  
  22. '** Transmits CAN's **
  23.  
  24. '** read message form line 25 **
  25.  
  26. '** write onto line 25
  27.  
  28.  
  29. Function MatchBaud (BaudString$)
  30.   MatchBaud = -1
  31.   If BaudString$ = "300" Then MatchBaud = 0
  32.   If BaudString$ = "600" Then MatchBaud = 1
  33.   If BaudString$ = "1200" Then MatchBaud = 2
  34.   If BaudString$ = "2400" Then MatchBaud = 3
  35.   If BaudString$ = "4800" Then MatchBaud = 4
  36.   If BaudString$ = "9600" Then MatchBaud = 5
  37.   If BaudString$ = "19200" Then MatchBaud = 6
  38.   If BaudString$ = "38400" Then MatchBaud = 7
  39.   If BaudString$ = "57600" Then MatchBaud = 8
  40.   If BaudString$ = "115200" Then MatchBaud = 9
  41. End Function
  42.  
  43. Sub ReadMsg (MsgString$, ByVal StartCol, ByVal MaxLength)
  44.   I = 0
  45.   Row = CSRLIN
  46.   Col = POS(0)
  47.   VIEW PRINT 25 TO 25
  48.   COLOR HighVideo
  49.   MsgString$ = ""
  50.   'input text from user
  51.   LOCATE 25, StartCol, 1
  52.   Do
  53.     AnyKey$ = INKEY$
  54.     If AnyKey$ <> "" Then
  55.       Select Case Left$(AnyKey$, 1)
  56.         Case Chr$(13)
  57.           COLOR LowVideo
  58.           VIEW PRINT 1 TO 24
  59.           LOCATE Row, Col, 1
  60.           Exit Sub
  61.         Case Chr$(27)  'Escape
  62.           'return empty string
  63.           MsgString$ = ""
  64.           COLOR LowVideo
  65.           VIEW PRINT 1 TO 24
  66.           LOCATE Row, Col, 1
  67.           Exit Sub
  68.         Case Chr$(8) 'backspace
  69.           'back up if can
  70.           If I > 0 Then
  71.             'adjust buffer
  72.             I = I - 1
  73.             MsgString$ = Left$(MsgString$, Len(MsgString$) - 1)
  74.             'write blank at cursor
  75.             LOCATE 25, StartCol + I, 1
  76.             Print " ";
  77.             LOCATE 25, StartCol + I, 1
  78.           End If
  79.         Case Else 'not one of above special chars
  80.           'display on bottom line
  81.           LOCATE 25, StartCol + I, 1
  82.           Print AnyKey$;
  83.           'save character
  84.           I = I + 1
  85.           MsgString$ = MsgString$ + AnyKey$
  86.           'done ?
  87.           If I >= MaxLength Then
  88.             VIEW PRINT 1 TO 24
  89.             COLOR LowVideo
  90.             LOCATE Row, Col, 1
  91.             Exit Sub
  92.           End If
  93.       End Select
  94.     End If
  95.   Loop
  96. End Sub
  97.  
  98. Sub TxCAN (ByVal Port)
  99.   For I = 1 To 6
  100.     Code = SioPutc(Port, CAN)
  101.   Next I
  102. End Sub
  103.  
  104. Sub WriteMsg (MsgString$, ByVal StartCol)
  105.   Col = POS(0)
  106.   Row = CSRLIN
  107.   VIEW PRINT 25 TO 25
  108.   COLOR HighVideo
  109.   LOCATE 25, StartCol, 1
  110.   Print String$(40, " ");
  111.   LOCATE 25, StartCol, 1
  112.   Print MsgString$;
  113.   VIEW PRINT 1 TO 24
  114.   COLOR LowVideo
  115.   LOCATE Row, Col, 1
  116. End Sub
  117.  
  118.